/*
 * @Author: szx
 * @Date: 2022-03-18 14:01:16
 * @LastEditTime: 2022-03-18 14:19:43
 * @Description:
 * @FilePath: \leetcode\剑指offer\14\14.js
 */
/**
 * @param {number} n
 * @return {number}
 */
var cuttingRope = function (n) {
    // dp[i]表示长度为i的绳子剪成m段后的最大乘积
    const dp = new Array(n + 1).fill(0);
    dp[2] = 1;
    for (let i = 3; i <= n; i++) {
        for (let j = 2; j < i; j++) {
            dp[i] = Math.max(dp[i], Math.max((i - j) * j, dp[i - j] * j));
        }
    }
    return dp[n];
};
